package com.dal.db.bean;

import com.dal.db.cache.ActivateCodeCache;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import static com.dal.db.StaticResource.ActivateCodeResource.*;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static com.dal.db.StaticResource.ActivateCodeResource.*;
/**
 * 激活码
 */
public class ActivateCode extends BasePojo<ActivateCode> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[2];
	
	/**
	* id
	*/
	private int id;
	
	/**
	* 创建时间
	*/
	private java.util.Date createDate;
	
	/**
	* 修改时间
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 邀请码
	*/
	private String invitationCode;
	
	/**
	* 是否已经使用
	*/
	private boolean used;
	
	/**
	* 激活码类型
	*/
	private String type;
	
	/**
	* 最大使用次数
	*/
	private String maxUseCount;
	
	/**
	* 奖励ID
	*/
	private String rewardId;
	
	/**
	* 激活uid
	*/
	private String uid;
	
	
	@Deprecated
	public static ActivateCode builder() {
		ActivateCode activateCode = new ActivateCode();
		return activateCode;
	}
	
	@Deprecated
	public ActivateCode() {
		super();
	}
	
	public ActivateCode(int id, String invitationCode, boolean used, String type, String maxUseCount, String rewardId, String uid) {
		super();
		this.id = id;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.invitationCode = invitationCode;
		this.used = used;
		this.type = type;
		this.maxUseCount = maxUseCount;
		this.rewardId = rewardId;
		this.uid = uid;
	}
	
	/**
	 * id
	 */
	public int getId() {return id;}
	
	/**
	 * id
	 */
	public ActivateCode setId(int id) {this.id = id;return this;}
	
	/**
	 * 创建时间
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * 创建时间
	 */
	protected ActivateCode setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * 修改时间
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * 修改时间
	 */
	protected ActivateCode setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 邀请码
	 */
	public String getInvitationCode() {return invitationCode;}
	
	/**
	 * 邀请码
	 */
	public ActivateCode setInvitationCode(String invitationCode) {this.invitationCode = invitationCode;return this;}
	
	/**
	 * 是否已经使用
	 */
	public boolean isUsed() {return used;}
	
	/**
	 * 是否已经使用
	 */
	public ActivateCode setUsed(boolean used) {this.used = used;return this;}
	
	/**
	 * 激活码类型
	 */
	public String getType() {return type;}
	
	/**
	 * 激活码类型
	 */
	public ActivateCode setType(String type) {this.type = type;return this;}
	
	/**
	 * 最大使用次数
	 */
	public String getMaxUseCount() {return maxUseCount;}
	
	/**
	 * 最大使用次数
	 */
	public ActivateCode setMaxUseCount(String maxUseCount) {this.maxUseCount = maxUseCount;return this;}
	
	/**
	 * 奖励ID
	 */
	public String getRewardId() {return rewardId;}
	
	/**
	 * 奖励ID
	 */
	public ActivateCode setRewardId(String rewardId) {this.rewardId = rewardId;return this;}
	
	/**
	 * 激活uid
	 */
	public String getUid() {return uid;}
	
	/**
	 * 激活uid
	 */
	public ActivateCode setUid(String uid) {this.uid = uid;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.createDate;
        values[2] = this.modifiedDate;
        values[3] = this.invitationCode;
        values[4] = this.used;
        values[5] = this.type;
        values[6] = this.maxUseCount;
        values[7] = this.rewardId;
        values[8] = this.uid;
        return values;
	}
	
	public ActivateCode deepCopy(){
		ActivateCode activateCode = null;
		try {
			activateCode = (ActivateCode) super.clone();
		    activateCode.setCreateDate(ToolCopy.copyObject(this.createDate));
		    activateCode.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    activateCode.indexValues = ArrayUtils.clone(indexValues);
			return activateCode;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return activateCode;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.createDate);
        map.put(keys[2], this.modifiedDate);
        map.put(keys[3], this.invitationCode);
        map.put(keys[4], this.used);
        map.put(keys[5], this.type);
        map.put(keys[6], this.maxUseCount);
        map.put(keys[7], this.rewardId);
        map.put(keys[8], this.uid);
        return map;
    }
    
    protected ActivateCode createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.createDate = (java.util.Date)map.get(keys[1]);
   		this.modifiedDate = (java.util.Date)map.get(keys[2]);
   		this.invitationCode = (String)map.get(keys[3]);
   		this.used = (boolean)map.get(keys[4]);
   		this.type = (String)map.get(keys[5]);
   		this.maxUseCount = (String)map.get(keys[6]);
   		this.rewardId = (String)map.get(keys[7]);
   		this.uid = (String)map.get(keys[8]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.createDate);
        obj.put(keys[2], this.modifiedDate);
        obj.put(keys[3], this.invitationCode);
        obj.put(keys[4], this.used);
        obj.put(keys[5], this.type);
        obj.put(keys[6], this.maxUseCount);
        obj.put(keys[7], this.rewardId);
        obj.put(keys[8], this.uid);
        return obj;
    }
    
    protected ActivateCode createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.createDate = obj.getDate(keys[1]);
	    this.modifiedDate = obj.getDate(keys[2]);
	    this.invitationCode = obj.getString(keys[3]);
	    this.used = obj.getBooleanValue(keys[4]);
	    this.type = obj.getString(keys[5]);
	    this.maxUseCount = obj.getString(keys[6]);
	    this.rewardId = obj.getString(keys[7]);
	    this.uid = obj.getString(keys[8]);
        return this;
    }
    
    
    public ActivateCode createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getInt(SOURCE_COLUMN_NAMES[0]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[1]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[2]);
	    this.invitationCode = rs.getString(SOURCE_COLUMN_NAMES[3]);
	    this.used = rs.getBoolean(SOURCE_COLUMN_NAMES[4]);
	    this.type = rs.getString(SOURCE_COLUMN_NAMES[5]);
	    this.maxUseCount = rs.getString(SOURCE_COLUMN_NAMES[6]);
	    this.rewardId = rs.getString(SOURCE_COLUMN_NAMES[7]);
	    this.uid = rs.getString(SOURCE_COLUMN_NAMES[8]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeString(this.invitationCode);
	    byteBuf.writeBoolean(this.used);
	    byteBuf.writeString(this.type);
	    byteBuf.writeString(this.maxUseCount);
	    byteBuf.writeString(this.rewardId);
	    byteBuf.writeString(this.uid);
    }
	
	protected ActivateCode readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.invitationCode = byteBuf.readString(null);
	    this.used = byteBuf.readBoolean(null);
	    this.type = byteBuf.readString(null);
	    this.maxUseCount = byteBuf.readString(null);
	    this.rewardId = byteBuf.readString(null);
	    this.uid = byteBuf.readString(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public ActivateCode insert(){
    	return ActivateCodeCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public ActivateCode update(){
    	return ActivateCodeCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return ActivateCodeCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public ActivateCode insertAndFlush(){
    	return ActivateCodeCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public ActivateCode updateAndFlush(){
    	return ActivateCodeCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return ActivateCodeCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public ActivateCode syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getInvitationCode()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((int)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}